# import the necessary packages
import cv2 as cv
import numpy as np

# first, let's draw a rectangle
rectangle = np.zeros((300, 300), dtype="uint8")
cv.rectangle(rectangle, (25, 25), (275, 275), 255, -1)
cv.imshow("Rectangle", rectangle)

# secondly,let's draw a circle
circle = np.zeros((300, 300), dtype="uint8")
cv.circle(circle, (150, 150), 150, 255, -1)
cv.imshow("Circle", circle)
cv.waitKey(0)
# A bitwise "AND" is only True when both rectangle and circle have
# a value that is "ON." Simpy put,the bitwise AND function
# examines every pixel in rectangle and circle. if both pixels
# have a value greater than zero,that pixel is turned "ON" (i.e
# set to 255 in the output image). if both pixels are not greater
# than zero ,then the output pixel is left "OFF" with a value of 0.
bitwiseAnd = cv.bitwise_and(rectangle,circle)
cv.imshow("AND",bitwiseAnd)
cv.waitKey(0)

# A bitwise "OR" examines every pixel in ractangle and circle. if
# EITHER pixel in rectangle or circle is greater than zero,then
# the output pixel has a value of 255,otherwise it is 0.
bitwiseOr = cv.bitwise_or(rectangle,circle)
cv.imshow("OR",bitwiseOr)
cv.waitKey(0)

# the bitwise "XOR" is indentical to the "OR" function,with one exception:
# both rectangle and circle are not allowed to BOTH
# have values greater than 0.
bitwiseXor = cv.bitwise_xor(rectangle,circle)
cv.imshow("XOR",bitwiseXor)
cv.waitKey(0)

# Finnaly,the bitwise "NOT" inverts the values of the pixels. Pixels
# with a value of 255 become 0,and pixels with a value of 0 become
# 255
bitwiseNot = cv.bitwise_not(circle)
cv.imshow("NOT",bitwiseNot)
cv.waitKey(0)